<template>
  <div class="businessUnit">
    <topBar :title="title"></topBar>
    <div class="connet">
      <div class="text">
        <div>
          <div class="cont">
            <div class="square"></div>
            <div class="value">{{ monthFrom }}</div>
          </div>
          <p><span class="circle"></span>{{ increaseFrom }}</p>
          <p><span class="circle"></span>{{ downFrom }}</p>
        </div>
        <div>
          <div class="cont">
            <div class="square"></div>
            <div class="value">{{ allFrom }}</div>
          </div>
          <p><span class="circle"></span>{{ downText }}</p>
          <p><span class="circle"></span>{{ downThree }}</p>
        </div>
        <div>
          <div class="cont">
            <div class="square"></div>
            <div class="value">{{ allBudget }}</div>
          </div>
          <p><span class="circle"></span>{{ frontBudget }}</p>
          <p><span class="circle"></span>{{ laterBudget }}</p>
        </div>
      </div>
      <div class="table">
        <el-table
          :data="tableData"
          border
          :cell-style="cellStyle"
          :header-cell-style="{
            background: '#C00000',
            color: '#ffffff',
            padding: '0',
            height: '26px',
          }"
        >
          <el-table-column
            label="经营单元"
            prop="displayName"
            align="center"
          ></el-table-column>
          <el-table-column label="当月环比" align="center">
            <el-table-column
              :label="acctMonth + '月当月收入'"
              align="center"
              prop="monthIncome"
            ></el-table-column>
            <el-table-column
              label="环比"
              align="center"
              prop="monthHbInreaseAmt"
            ></el-table-column>
            <el-table-column
              label="环比增幅"
              align="center"
              prop="monthHbInrease"
            >
              <template slot-scope="scope">
                <div>
                  {{ scope.row.monthHbInrease + "%" }}
                </div>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="累计同比" align="center">
            <el-table-column
              :label="acctMonth + '月累计收入'"
              align="center"
              prop="yearIncome"
            ></el-table-column>
            <el-table-column
              label="累计同比"
              align="center"
              prop="yearTbInreaseAmt"
            ></el-table-column>
            <el-table-column
              label="累计同比增幅"
              align="center"
              prop="yearTbInrease"
            >
              <template slot-scope="scope">
                <div >
                  {{ scope.row.yearTbInrease + "%" }}
                </div>
              </template>
            </el-table-column>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import topBar from "./topBar";
import { growthSituation } from "@/api/codeIncome/analysis";
export default {
  name: "businessUnit",
  components: {
    topBar,
  },
  props: {
    searchData: {
      type: Object,
      default: {},
    },
  },
  watch: {
    searchData: {
      handler(newName) {
          this.getData();
      },
      deep: true,
    },
  },
  data() {
    return {
      title: "码号收入 – 经营单元增长情况",
      acctMonth: "",
      monthFrom: "",
      increaseFrom: "",
      downFrom: "",
      allFrom: "",
      downText: "",
      downThree: "",
      allBudget: '',
      frontBudget: '',
      laterBudget: '',
      tableData: [],
    };
  },
  created() {},
  mounted() {
    this.getData();
  },
  methods: {
    cellStyle({row, column, rowIndex, columnIndex}) {
        if (row.tbColorSign == "TB_UP_0" && column.label == '累计同比增幅') {
            return "background: #5A8AC6;padding:0;color:black"
        } else if (row.tbColorSign == "TB_UP_1" && column.label == '累计同比增幅') {
            return "background: #7BA1D2;padding:0;color:black"
        } else if (row.tbColorSign == 'TB_UP_2' && column.label == '累计同比增幅') {
            return "background: #D9E4F3;padding:0;color:black"
        } else if (row.tbColorSign == 'TB_DOWN_0' && column.label == '累计同比增幅') {
            return "background: #F8696B;padding:0;color:black"
        } else if (row.tbColorSign == 'TB_DOWN_1' && column.label == '累计同比增幅') {
            return "background: #F98E95;padding:0;color:black"
        } else if (row.tbColorSign == 'TB_DOWN_2' && column.label == '累计同比增幅') {
            return "background: #FABCBE;padding:0;color:black"
        } else if (row.hbColorSign == "HB_UP_0" && column.label == '环比增幅') {
            return "background: #5A8AC6;padding:0;color:black"
        } else if (row.hbColorSign == "HB_UP_1"  && column.label == '环比增幅') {
            return "background: #7BA1D2;padding:0;color:black"
        } else if (row.hbColorSign == 'HB_UP_2'  && column.label == '环比增幅') {
            return "background: #D9E4F3;padding:0;color:black"
        } else if (row.hbColorSign == 'HB_DOWN_0' && column.label == '环比增幅') {
            return "background: #F8696B;padding:0;color:black"
        } else if (row.hbColorSign == 'HB_DOWN_1' && column.label == '环比增幅') {
            return "background: #F98E95;padding:0;color:black"
        } else if (row.hbColorSign == 'HB_DOWN_2' && column.label == '环比增幅') {
            return "background: #FABCBE;padding:0;color:black"
        }
        if (row.displayName == '杭州') {
            return 'font-weight:bold;color:black;padding:0;'
        }
        return "color:black;padding:0"
    },
    // 获取码号收入整体趋势
    getData() {
      growthSituation({
        acctMonth: this.searchData.acctMonth,
        areaId: this.searchData.areaId,
      }).then((res) => {
        if (res.code == 200) {
          this.acctMonth = res.data.acctMonth;
          res.data.characterList.map((item) => {
            if (item.code == "MSG1") {
              this.monthFrom = item.text;
            } else if (item.code == "MSG2") {
              this.increaseFrom = item.text;
            } else if (item.code == "MSG3") {
              this.downFrom = item.text;
            } else if (item.code == "MSG4") {
              this.allFrom = item.text;
            } else if (item.code == "MSG5") {
              this.downText = item.text;
            } else if (item.code == "MSG6") {
              this.downThree = item.text;
            } else if (item.code == "MSG7") {
              this.allBudget = item.text;
            } else if (item.code == "MSG8") {
              this.frontBudget = item.text;
            } else {
              this.laterBudget = item.text
            }
          });
          this.tableData = res.data.unitInreaseList;
        }
      });
    },
  },
};
</script>

<style scoped>
.businessUnit {
  box-sizing: border-box;
  padding: 20px;
  box-shadow: 0px 0px 10px 1px rgb(0 0 0 / 15%);
}
</style>

<style scoped lang="scss">
.businessUnit {
  margin-top: 20px;
}
.connet {
  box-sizing: border-box;
  padding: 0 20px;
  margin-top: 10px;
  .text {
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    .cont {
      font-size: 24px;
      line-height: 44px;
      display: flex;
    }
    .square {
      margin-top: 15px;
      margin-right: 15px;
      width: 10px;
      height: 10px;
      background: #c00000;
      transform: rotate(45deg);
    }
    .value {
      flex: 1;
      flex-wrap: wrap;
    }
    p {
      display: flex;
      align-items: center;
      padding-left: 40px;
      font-size: 20px;
      .circle {
        width: 4px;
        height: 4px;
        background-color: #c0504d;
        border-radius: 50%;
        display: inline-block;
        margin-right: 10px;
      }
    }
  }
  .table {
    width: 100%;
  }
  /deep/ .el-table {
    width: 100%;
  }
}
</style>
